<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <meta charset="UTF-8">
    <title>选择变更表单</title>
</head>
<body>
<div style="max-width: 450px;max-height: 450px;">
    <form id="form" role="form" method="post" th:action="${action}">
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label for="stage">选择变更表单</label>
                    <select class="form-control" id="stage" name="stage">
                        <option th:each="model:${changeFroms}"
                                th:value="${model.getId()}"
                                th:text="${model.getChangeNo()}"
                        >
                        </option>
                    </select>
                </div>
            </div>
            <!--<div class="panel-body">-->
                <!--<div class="col-lg-6">-->
                    <!--<label>请展开部门选择人员</label>-->
                    <!--<ul id="orgGroupTree" class="ztree" style="width:400px; overflow:auto;"></ul>-->
                <!--</div>-->
                <!--<div class="col-lg-6">-->
                    <!--<div class="form-group col-lg-12">-->
                        <!--<label th:for="${typeName}">关联工程师名:</label>-->
                        <!--<input type="text" class="form-control" th:id="${typeName}" th:name="${typeName}"-->
                               <!--placeholder="请选择工程师"-->
                        <!--/>-->
                    <!--</div>-->
                    <!--<div class="form-group col-lg-12">-->
                        <!--<label>所属部门:</label>-->
                        <!--<input type="text" class="form-control" id="dept"-->
                               <!--disabled="disabled"-->
                        <!--/>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
        </div>
    </form>
</div>
<script th:inline="javascript">
    <![CDATA[
    var setting = {
        check: {
            enable: false
        },
        view: {
            dblClickExpand: false,
            showLine: true,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "uid",
                pIdKey: "pUid",
                rootPId: "0"
            }
        },
        callback: {
            beforeClick: function (treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj('orgGroupTree');
                if (treeNode.isParent) {
                    zTree.expandNode(treeNode);
                    return false;
                } else {
                    return true;
                }
            },
            onClick: function (event, treeId, treeNode) {
                console.log(treeId);
                console.log($("#selectOption").val());
                let userId = treeNode.uid;
                $.ajax({
                    type: "GET",
                    //ajax需要添加打包名
                    url: "./vwo/getUserDetail?uid=" + userId,
                    success: function (result) {
                        if (result.status) {
                            $("#dept").val(result.groupName);
                            $("#selectedUserId").val(result.personId);
                            $("#" + $("#selectOption").val()).val(result.personName);

                        }
                    },
                    error: function (e) {
                        console.error("连接服务器异常:" + e.status);
                    }
                });
            }
        }
    };
    $(
        initZTree = function () {
            $.post("./vwo/getUserAndGroup", function (info) {
                var t = $("#orgGroupTree");
                t = $.fn.zTree.init(t, setting, info.data);
            })
        }
    );


    var rows = [[${beans}]];
    var projectPuid = getProjectUid();
    $(function () {
        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            var changeFromId = $("#stage option:selected").val();
            $.ajax({
                type: "POST",
                //ajax需要添加打包名
                url: "./vwoProcess/featureGetIntoVWO?projectUid="+projectPuid+"&changeFromId="+changeFromId,
                data: JSON.stringify(rows),
                contentType: "application/json",
                success: function (result) {
                    // $('.modal-dialog', window.top.document).parent('div').remove()
                    // $('body', window.top.document).find('.modal-backdrop').remove();
                    // $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.doQuery();
                    activeTabBodyRefresh();
                    // if (result.status) {
                    if (result.status) {
                        layer.msg(result.msg, {icon: 1, time: 2000});
                    }
                    // window.Ewin.alert({message: result, width: 800});
                    //刷新，会重新申请数据库数据
                    // }
                    else {
                        window.Ewin.alert({message: result.msg});
                    }
                    $table.bootstrapTable("refresh");
                },
                error: function (info) {
                    window.Ewin.alert({message: "操作发送失败:" + info.status});
                }
            })
        });
    })
    ]]>
</script>
</body>
</html>